package com.hsurosy.hsuchain.nft.limiter.configuration;

import com.hsurosy.hsuchain.nft.limiter.SlidingWindowRateLimiter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 限流器配置类
 *
 * @Author Hsu琛君珩
 * @Date 2024-10-05 4:34
 * @Description
 * @Version: v1.0.0
 */
@Configuration
public class RateLimiterConfiguration {

    /**
     * 创建滑动窗口限流器的 Bean
     *
     * @param redisson Redisson 客户端实例，用于管理分布式锁和限流
     * @return SlidingWindowRateLimiter 实例
     */
    @Bean
    public SlidingWindowRateLimiter slidingWindowRateLimiter(RedissonClient redisson) {
        // 返回一个基于 Redisson 的滑动窗口限流器实例
        return new SlidingWindowRateLimiter(redisson);
    }
}
